package com.wrupple.muba.common.shared;

import java.util.List;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.wrupple.muba.common.client.activity.ActivityProcess;
import com.wrupple.muba.common.domain.DesktopPlace;
import com.wrupple.muba.common.domain.FilterData;
import com.wrupple.muba.widget.client.view.Task;

/**
 * 
 * Changes or creates data from an input and notifies when it is done
 * 
 * @author japi
 * 
 */
public interface State<I, O> {

	public interface ProcessManager {

		<I, O> void processSwitch(com.wrupple.muba.common.shared.Process<I, O> process, String localizedName, I input,
				StateTransition<O> callback,EventBus bus);
		
		void contextSwitch(ActivityProcess activityState, String localizedName,
				AcceptsOneWidget container, EventBus bus);
	}

	public interface StorageManager {
		
		Transaction startTransaction();

		void create(String type,JavaScriptObject entry, final StateTransition<? extends JavaScriptObject> callback);

		void read(String type, String id, final StateTransition<? extends JavaScriptObject> callback);
		
		<T extends JavaScriptObject> void read(String type, FilterData filter, StateTransition<List<T>> callback);
		
		<T extends JavaScriptObject> void summary(String type, FilterData filter,
				StateTransition<List<T>> rangeReceived);
		
		void update(String type,String id,JavaScriptObject entry, final StateTransition<? extends JavaScriptObject> callback);
		
		void delete(String type,String id, final StateTransition<? extends JavaScriptObject> callback);

		<T extends JavaScriptObject>  void read(String catalog, List<String> ids,
				StateTransition<List<T>> retailersCallback);

		

	}
	
	public interface DesktopManager {
		void exit();
		
		void endUserSession();

		DesktopPlace getDefaultPlace();

		DesktopPlace getWhere();
		
		void goTo(DesktopPlace place);
		
		public <T extends JavaScriptObject> T getUser();

		AcceptsOneWidget getOutputFeature();

		void restoreTask(Task<?, ?> currentTask);

		void setUserObject(JavaScriptObject userData);

	}

	public interface Context {

		ServiceBus getServiceBus();

		AcceptsOneWidget getOutputFeature();
		
		StorageManager getStorageManager();

		ProcessManager getProcessManager();

		DesktopManager getDesktopManager();
		

	}

	public interface ContextAware<I, O> extends State<I, O> {

		void setContext(Context context);

	}

	 void start(final I parameter, final StateTransition<O> onDone,EventBus bus);
}
